import request from '@/utils/request';
import type { CurrentUser } from '@/pages/admin/UserManager/components/data';
import type { ResultType } from './type';

export type FindUserType = {
  userName?: string;
  _id?: string;
  email?: string;
  phone?: number;
  roleName?: string;
  startTime?: string;
  endTime?: string;
};

export async function getUserList(params): Promise<ResultType> {
  return request('/api/v1/user/getList', {
    method: 'GET',
    params,
  });
}

export async function findCurrent(params: { id: number }): Promise<ResultType> {
  return request('/api/v1/currentUser', {
    method: 'GET',
    params,
  });
}

export async function updateUser(params: CurrentUser): Promise<ResultType> {
  return request('/api/v1/user/updateRecord', {
    method: 'PUT',
    data: params,
  });
}
export async function updatePwd(params: { password: string; id: string }): Promise<ResultType> {
  return request('/api/v1/user/updatePwd', {
    method: 'PUT',
    data: params,
  });
}

export async function createUser(params: CurrentUser): Promise<ResultType> {
  return request('/api/v1/user/createRecord', {
    method: 'POST',
    data: params,
  });
}
export async function deleteUser(params: { id: number }) {
  return request(`/api/v1/user/deleteRecord/${params.id}`, {
    method: 'DELETE',
  });
}
export async function queryNotices(): Promise<ResultType> {
  return request('/api/notices');
}

export async function upload(params): Promise<ResultType> {
  return request('/api/v1/upload', {
    method: 'POST',
    data: params,
  });
}
